package inutan.common.kit;

import inutan.common.constant.DataConstant;
import inutan.common.inner.protocol.InnerMessage;
import org.ricks.net.DataCodecKit;
import java.util.HashSet;


/**
 * @author chenwei
 * @Description: 对外
 * @date 2023/2/1015:49
 */
public class InnerKit {


    /**
     * 创建请求消息
     *
     * @param data     业务数据
     * @return 请求消息
     */
    public static InnerMessage createInnerMessage(short cmd, Object data) {
        byte[] bytes = null;

        if (data != null) {
            bytes = DataCodecKit.encode(data);
        }

        return createInnerMessage(cmd, bytes);
    }

    /**
     * 创建请求消息
     *
     * @return 请求消息
     */
    public static InnerMessage createInnerMessage(short cmd) {
        return createInnerMessage(cmd, null);
    }

    /**
     * 创建请求消息
     *
     * @param data     业务数据 byte[]
     * @return 请求消息
     */
    public static InnerMessage createInnerMessage(short cmd, byte[] data) {

        // 请求
        InnerMessage innerMessage = new InnerMessage();
        innerMessage.cmd = cmd;
        innerMessage.data = data;
        innerMessage.state = DataConstant.RUTE_MESSAGE;
        innerMessage.toUserIds = new HashSet<>();
        innerMessage.groupId = "";
        return innerMessage;
    }


}
